
import { Controller, Get, Post, Body, Patch, Param, Delete, Query } from '@nestjs/common';
import { PaginationResult } from '@/common/interface/pagination.interface';
import { ApiTags } from '@nestjs/swagger';

import { RoleService } from './role.service';
import { CreateRoleDto } from './dto/create-role.dto';
import { UpdateRoleDto } from './dto/update-role.dto';
import { QueryRoleDto } from './dto/query-role.dto';
import { RoleEntity } from './entities/role.entity';
import { ApiOperation } from '@nestjs/swagger';

@ApiTags('role')
@Controller('role')
export class RoleController {
  constructor(private readonly service: RoleService) { }

  @Post()
  @ApiOperation({ summary: '创建role' })
  create(@Body() createDto: CreateRoleDto) {
    return this.service.create(createDto);
  }

  @Get()
  @ApiOperation({ summary: '获取role列表' })
  async findAll(@Query() query: QueryRoleDto): Promise<PaginationResult<RoleEntity>> {
    return this.service.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取role' })
  findOne(@Param('id') id: number) {
    return this.service.findOne(+id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新role' })
  update(@Param('id') id: number, @Body() updateDto: UpdateRoleDto) {
    return this.service.update(+id, updateDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除role' })
  remove(@Param('id') id: number) {
    return this.service.remove(+id);
  }
}
